package com.hanxiaozhang.api.fegin.base.fallback;

import com.hanxiaozhang.api.fegin.base.BaseFeignClient;
import com.hanxiaozhang.base.entity.LogEntity;
import com.hanxiaozhang.result.Result;
import com.hanxiaozhang.result.ResultCode;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author hanxinghua
 * @create 2021/4/8
 * @since 1.0.0
 */
@Slf4j
@Component
public class BaseFeignClientFallbackFactory implements FallbackFactory<BaseFeignClient> {
    @Override
    public BaseFeignClient create(Throwable throwable) {

        return new BaseFeignClient() {

            @Override
            public Result<Void> save(LogEntity logEntity) {
                log.error("BaseFeignClientFallbackFactory-save:[{}]", throwable);
                return Result.error(ResultCode.HYSTRIX_FUSING, throwable, HttpStatus.INTERNAL_SERVER_ERROR);
            }

            @Override
            public Result uploadFile(MultipartFile file, String type, String fileTag) {
                log.error("BaseFeignClientFallbackFactory-uploadFile:[{}]", throwable);
                return Result.error(ResultCode.HYSTRIX_FUSING, throwable, HttpStatus.INTERNAL_SERVER_ERROR);
            }
        };
    }
}
